﻿using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;

namespace blog.Entity;

public partial class BlogContext : DbContext
{
    public BlogContext()
    {
    }

    public BlogContext(DbContextOptions<BlogContext> options)
        : base(options)
    {
    }

    public virtual DbSet<ArticleContent> ArticleContents { get; set; }

    public virtual DbSet<ArticleInfo> ArticleInfos { get; set; }

    public virtual DbSet<ArticleTag> ArticleTags { get; set; }

    public virtual DbSet<ArticleType> ArticleTypes { get; set; }

    public virtual DbSet<SysAuth> SysAuths { get; set; }

    public virtual DbSet<SysGroup> SysGroups { get; set; }

    public virtual DbSet<SysUser> SysUsers { get; set; }

    public virtual DbSet<UserAvatar> UserAvatars { get; set; }

    public virtual DbSet<UserLog> UserLogs { get; set; }

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see http://go.microsoft.com/fwlink/?LinkId=723263.
        => optionsBuilder.UseSqlServer("Server=.;Database=Blog;Integrated Security=SSPI;TrustServerCertificate=true;");

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<ArticleContent>(entity =>
        {
            entity.ToTable("ArticleContent");

            entity.Property(e => e.article_content)
                .HasComment("文章内容")
                .HasColumnType("text");
            entity.Property(e => e.article_id).HasComment("文章id");
        });

        modelBuilder.Entity<ArticleInfo>(entity =>
        {
            entity.ToTable("ArticleInfo");

            entity.Property(e => e.front)
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasComment("封面");
            entity.Property(e => e.is_delete).HasComment("是否删除");
            entity.Property(e => e.like_num).HasComment("喜欢数");
            entity.Property(e => e.title)
                .HasMaxLength(255)
                .IsUnicode(false)
                .HasComment("标题");
            entity.Property(e => e.view_num).HasComment("浏览量");
            entity.Property(e => e.write_time)
                .HasComment("编写时间")
                .HasColumnType("datetime");
            entity.Property(e => e.writer)
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasComment("作者");
        });

        modelBuilder.Entity<ArticleTag>(entity =>
        {
            entity.ToTable("ArticleTag");

            entity.Property(e => e.is_delete).HasComment("是否删除");
            entity.Property(e => e.tag_name)
                .HasMaxLength(50)
                .IsUnicode(false);
        });

        modelBuilder.Entity<ArticleType>(entity =>
        {
            entity.ToTable("ArticleType");

            entity.Property(e => e.is_delete).HasComment("是否删除");
            entity.Property(e => e.parent_id).HasComment("父类id");
            entity.Property(e => e.type_name)
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasComment("类别名称");
        });

        modelBuilder.Entity<SysAuth>(entity =>
        {
            entity.ToTable("SysAuth");

            entity.Property(e => e.auth_name)
                .HasMaxLength(50)
                .IsUnicode(false);
        });

        modelBuilder.Entity<SysGroup>(entity =>
        {
            entity.ToTable("SysGroup");

            entity.Property(e => e.id).HasComment("权限组id");
            entity.Property(e => e.group_name)
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasComment("权限组名称");
            entity.Property(e => e.is_delete).HasComment("是否删除");
        });

        modelBuilder.Entity<SysUser>(entity =>
        {
            entity.ToTable("SysUser");

            entity.Property(e => e.id).HasComment("自增用户id");
            entity.Property(e => e.email)
                .HasMaxLength(255)
                .IsUnicode(false)
                .HasComment("邮箱");
            entity.Property(e => e.group_id).HasComment("用户组id");
            entity.Property(e => e.is_delete).HasComment("是否删除");
            entity.Property(e => e.nickname)
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasComment("昵称");
            entity.Property(e => e.password)
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasComment("密码");
            entity.Property(e => e.status)
                .HasDefaultValueSql("((1))")
                .HasComment("状态 0-禁用 1-启用");
            entity.Property(e => e.username)
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasComment("账号");
        });

        modelBuilder.Entity<UserAvatar>(entity =>
        {
            entity.ToTable("UserAvatar");

            entity.Property(e => e.avatar)
                .HasMaxLength(50)
                .IsUnicode(false);
        });

        modelBuilder.Entity<UserLog>(entity =>
        {
            entity.ToTable("UserLog");

            entity.Property(e => e.ip)
                .HasMaxLength(255)
                .IsUnicode(false);
            entity.Property(e => e.location)
                .HasMaxLength(255)
                .IsUnicode(false);
            entity.Property(e => e.log_time).HasColumnType("datetime");
        });

        OnModelCreatingPartial(modelBuilder);
    }

    partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
}
